<?php

namespace App\Models\Purchase;


use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class PurchaseSettlePriceLog extends Model
{
    protected $table = 'purchase_settle_price_log';
    public $timestamps = false;
    protected $primaryKey = 'id';
    protected $guarded = ['_token'];
    /**
     *获取列表 
     */
    public static function getList(Request $request, $cpid)
    {
        $query = self::where(['cpid' => $cpid, 'is_del' => 1])->orderBy('create_at', 'desc');

        $status = $request->status;
        if (in_array($status, [1, 2])) {
            $query->where('status', $status);
        }
        $steel_factory_name = $request->steel_factory_name; //钢厂名称
        if ($steel_factory_name != '') {
            $query->where('steel_factory_name', 'like', '%' . $steel_factory_name . '%');
        }
        $start_time = strtotime($request->start_time)>0?strtotime($request->start_time):intval($request->start_time);
        $end_time = strtotime($request->end_time)>0?strtotime($request->end_time):intval($request->end_time);
        if ($start_time > 0 && $end_time > 0) {
            $query->where('update_at', '>=', $start_time)->where('update_at', '<=', $end_time);
        }

        $type = $request->type ?? 0;
        if ($type > 0) {
            $query->where('type', $type);
        }

        $limit = $request->limit ?? 10;
        $list = $query->paginate($limit)->toArray();
        return paginateDataToArray($list);
    }
}